<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class LoginUserApiController extends AbstractRestfulController
{
    public function getList()
    {
		
    }
    public function get($email)
    {
		header('Access-Control-Allow-Origin: *');		
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');		
		$checkUser = $userTable->checkUniqueRecord($email)->toarray();		
		if(count($checkUser)!=0){
			return new JsonModel(array(
				'data' => 'Email already exists',
				'value' => 1,
			));			
		}else{
			return new JsonModel(array(
				'data'  => 'Valid email',
				'value' => 0,
			));			
		}
    }
    public function create($data)
    {//echo '<pre>'; print_r($data);exit;
		header('Access-Control-Allow-Origin: *');	
		$userTable=$this->getServiceLocator()->get('Models\Model\UserFactory');
		if($data['user_type_id']=='1'){
			$checkUserloginemail = $userTable->checkloginEmail($data)->toArray();
				if(count($checkUserloginemail)!=0){
					$checkUser = $userTable->checkDetails($data)->current();
				}else{
					return new JsonModel(array(
						'value'		=>  0,
					));			
				}
		}else if($data['user_type_id']=='3'){
			$checkUserloginemail = $userTable->checkloginEmail($data)->toArray();
				if(count($checkUserloginemail)!=0){
					$checkUser = $userTable->checkDetails($data)->current();
				}else{
					return new JsonModel(array(
						'value'		=>  0,
					));			
				}
		}else{
			$checkUserloginemail = $userTable->checkloginEmail($data)->toArray();
				if(count($checkUserloginemail)!=0){
					$checkUser = $userTable->checkDetails($data)->current();
				}else{
					return new JsonModel(array(
						'UserDetails'		=>  0,
					));			
				}
		}
		if($checkUser){
			return new JsonModel(array(
				'UserDetails' 	=>  $checkUser,
				'value'		=>  1,
			));			
		}else{
			return new JsonModel(array(
			'status'	=>	'fail',
			'value'		=>  0,
			));			
		}
    }
    public function update($id, $data)
    {
        
    }
    public function delete($id)
    {
       
    }
}